CC = gcc
CFLAGS = -Wall -Wextra -std=c99
BUILD_DIR = build

# Default target
all: directories

# Create build directory
directories:
	@mkdir -p $(BUILD_DIR)

# Generic rules for compiling any C file
%: 01_Introduction/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 02_BasicSyntax/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 03_ControlFlow/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 04_Functions/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 05_Arrays/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 06_Pointers/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 07_Strings/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 08_Structures/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 09_LinkedLists/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 10_Recursion/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 11_FileIO/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

%: 12_Projects/%.c
	$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ $<

# Rules for C++ files
%: 01_Introduction/%.cpp
	g++ -Wall -Wextra -o $(BUILD_DIR)/$@ $<

%: 02_BasicSyntax/%.cpp
	g++ -Wall -Wextra -o $(BUILD_DIR)/$@ $<

%: 03_ControlFlow/%.cpp
	g++ -Wall -Wextra -o $(BUILD_DIR)/$@ $<

%: 04_Functions/%.cpp
	g++ -Wall -Wextra -o $(BUILD_DIR)/$@ $<

%: 05_Arrays/%.cpp
	g++ -Wall -Wextra -o $(BUILD_DIR)/$@ $<

%: 12_Projects/%.cpp
	g++ -Wall -Wextra -o $(BUILD_DIR)/$@ $<

# Clean build directory
clean:
	rm -rf $(BUILD_DIR)/*

.PHONY: all clean directories
